${page.setTitle("push-center| GOPS")}
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<style type="text/css">
    .l-table-edit {border:1px solid; margin : 10px 0px 10px 15px;padding: 10px 10px 10px 10px;}
    .l-table-edit2 {margin : 0px 0px 00px 15px;}
    .l-label-edit {margin : 15px;}
    .l-table-edit-td {width:80px; padding:4px;}
    .l-table-edit-tr {margin:10px;}
    .l-button-submit,.l-button-reset{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
</style>
${token()}
<div class="body-pla-content">
  <form action="" method="post" id="group" name="group">
        <br></br>
        <label class="l-label-edit">基本用户信息</label>
        <table class="l-table-edit" >
            <tr>
            	<td align="right" >   性别：</td>
                <td align="left" rows="1" colspan="3">
               		<input type="radio" name="gender" style="width: 30px" value="1">男</input>
					<input type="radio" name="gender" style="width: 30px" value="2">女</input>
				</td>
                <td align="right" style="width:50px">   年龄：</td>
                <td align="left" >
                	<input  name="age" type="text" id="age" style="width: 200px" value=""/>
                	<input  name="ageValue" type="hidden" id="ageValue" style="width: 280px" value=""/>
				</td>
			 </tr> 
            <tr class="l-table-edit-tr">
                <td align="right" >注册时间：</td>
                <td align="left" class="l-table-edit-td">
						<input name="registerdate1" type="text" id="registerdate1" style="width: 65px"/> 
				</td>
				<td align="center" >
						<label style="width: 30px">——</label>
				</td>
				<td align="right" class="l-table-edit-td">
						<input name="registerdate2" type="text" id="registerdate2"  style="width: 65px" />
				</td>
				<td align="right" >   地区：</td>
                <td align="left" >
						<select name="province" style="width: 200px" id="province" ">
							<option value="">-- 请选择 --</option>
							<#list provinces as t>
								<option value="${t.areaId}">${t.areaName}</option>
							</#list>
						 </select>
				</td>
            </tr>  
         </table>
         
         <label class="l-label-edit">高级用户特征</label>
         <table class="l-table-edit" > 
         	<tr>
            	<td align="right" >目前患病：</td>
                <td align="left" rows="1" colspan="3">
               		<input  name="disease" type="text" id="disease" style="width: 280px" value=""/>
				</td>
                <td align="right" > 曾患病：</td>
                <td align="left" rows="1" colspan="3">
					<input  name="diseasehis" type="text" id="diseasehis"  style="width: 200px" value=""/>
				</td>
			 </tr>
			 <tr>
            	<td align="right" > 活跃度：</td>
                <td align="left" rows="1" colspan="3">
                	<input  name="liveness" type="text" id="liveness" style="width: 280px" value=""/>
                	<input  name="livenessValue" type="hidden" id="livenessValue" style="width: 280px" value=""/>
				</td>
                <td align="right" >平台偏好：</td>
                <td align="left" rows="1" colspan="3">
                	<input  name="platformfav" type="text" id="platformfav" style="width: 280px" value=""/>
                	<input  name="platformfavValue" type="hidden" id="platformfavValue" style="width: 280px" value=""/>
				</td>
			 </tr>
			 <tr>
            	<td align="right" >就诊时间：</td>
                <td align="left" class="l-table-edit-td">
						<input name="lastorderdate1" type="text" id="lastorderdate1" style="width: 65px"/> 
				</td>
				<td align="center" >
						<label style="width: 20px">——</label>
				</td>
				<td align="right" class="l-table-edit-td">
						<input name="lastorderdate2" type="text" id="lastorderdate2"  style="width: 65px" />
				</td>
				 <td align="right" >
						<input name="owner" type="hidden" id="owner" value="${webUtil.getNickName()}"/>
				</td>
			 </tr>
         </table>
     </form>
     <br></br>
     <form action="" method="post" id="groupName" name="groupName">
         <table class="l-table-edit2">
         	<tr>
         		<td align="right" > 分组名：</td>
                <td align="left" class="l-table-edit-td">
						<input name="name" type="text" id="name"  style="width: 130px" value=""/>
				</td>
			</tr>
			<tr>
         		<td align="right" > 分组code：</td>
                <td align="left" class="l-table-edit-td">
						<input name="code" type="text" id="code"  style="width: 130px" value=""/>
				</td>
			</tr>
         </table>
         <br></br>
         <table class="l-table-edit2">
            <tr>
            	<td></td>
            	<td > <input type="button" value="保存分组" id="dosubmit" class="l-button l-button-submit"/>  </td>
            	<td align="left"></td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
function diseaseSearch(){
	var disease = $("#disease").val();
	$.ajax({
	        url: "${appServer}/disease/"+disease,   
	        type: "GET",
	        success: function(data, result) {
	        	if(result.hasError) {
					$.ligerDialog.error(result.message);
	        	}else{
	        		$("#disease").attr("value",data);
	        		//$.ligerDialog.success(result.message);
	        		//parent.window.search();
	        		//parent.$.ligerDialog.close();
	        		//parent.$.ligerDialog.hide();
	        	}
	        }
	    });
}
$(function () {
		$("#registerdate1").ligerDateEditor();
        $("#registerdate2").ligerDateEditor();
        $("#lastorderdate1").ligerDateEditor();
        $("#lastorderdate2").ligerDateEditor();
       	$("#age").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
                data: [
                    { text: '小于18岁', id: '[0,18)' },
                    { text: '18岁~24岁', id: '[18,25)' },
                    { text: '25岁~29岁', id: '[25,30)' },
                    { text: '30岁~34岁', id: '[30,35)' },
                    { text: '35岁~39岁', id: '[35,39)' },
                    { text: '40岁~44岁', id: '[40,45)' },
                    { text: '55岁~59岁', id: '[55,59)' },
                    { text: '大于60岁', id: '[60,120)' }
                ], valueFieldID: 'ageValue'
            });
        $("#liveness").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
                data: [
                    { text: '活跃用户', id: '1' },
                    { text: '睡眠用户', id: '2' },
                    { text: '流失用户', id: '3' }
                ], valueFieldID: 'livenessValue'
            });
		$("#platformfav").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
                data: [
                    { text: 'APP', id: '1' },
                    { text: '网站', id: '2' },
                    { text: '支付宝h5', id: '3' },
                    { text: '微医h5', id: '4' }
                ], valueFieldID: 'platformfavValue'
            });
        
		$("#dosubmit").click(function(){
			var ownerValue = $("#owner").val();
        	var code = $("#code").val();
			var conditionArray = $('#group').serializeArray(); 
			var nameArray = $('#groupName').serializeArray(); 
			var nameValue = nameArray[0].value;
			if(nameValue==""){
				$.ligerDialog.error('分组名称不可为空!');
			}
			var codeValue = nameArray[1].value;
			if(codeValue==""){
				$.ligerDialog.error('分组code不可为空!');
			}
			var ageValue = $("#ageValue").val();
			var livenessValue = $("#livenessValue").val();
			var platformfavValue = $("#platformfavValue").val();
			var ageArray = ageValue.split(";");
			var livenessArray = livenessValue.split(";");
			var platformfavArray = platformfavValue.split(";");
			var conditionStr = "";
			for(var i=0; i<conditionArray.length; i++){
				var name = conditionArray[i].name;
				var value = conditionArray[i].value;
				if(name == "registerdate1"){
					conditionStr=conditionStr+"registerdate"+"=["+value+",";
				}else if(name == "registerdate2"){
					conditionStr=conditionStr+value+")&";
				}else if(name == "lastorderdate1"){
					conditionStr=conditionStr+"lastorderdate"+"=["+value+",";
				}else if(name == "lastorderdate2"){
					conditionStr=conditionStr+value+")&";
				}else if(name == "age"){
					for(var j=0; j<ageArray.length; j++){
						conditionStr=conditionStr+name+"="+ageArray[j]+"&";
					}
				}else if(name == "liveness"){
					for(var j=0; j<livenessArray.length; j++){
						conditionStr=conditionStr+name+"="+livenessArray[j]+"&";
					}
				}else if(name == "platformfav"){
					for(var j=0; j<platformfavArray.length; j++){
						conditionStr=conditionStr+name+"="+platformfavArray[j]+"&";
					}
				}else if(name != "ageValue" && name != "livenessValue" && name != "platformfavValue"){
					conditionStr=conditionStr+name+"="+value+"&";
				}
			}
	    $.ajax({
	        url: "${appServer}/class/add.json",   
	        data: [{"name":"name","value":nameArray[0].value},{"name":"code","value":nameArray[1].value},
	        		{"name":"conditions","value":conditionStr},{"name":"type","value":1},{"name":"owner","value":ownerValue},
	        		{"name":"code","value":code}], 
	        type: "POST",
	        success: function(result) {
	        	if(result.hasError) {
					$.ligerDialog.error(result.message);
	        	}else{
	        		$.ligerDialog.success(result.message);
	        		parent.window.search();
	        		parent.$.ligerDialog.close();
	        		parent.$.ligerDialog.hide();
	        	}
	        }
	    });	
		return true;
	});
	
});

function listCitys(){
	var province = $('#province').val();
	var pText = $('#province').find("option:selected").text();
	var city0 = $('#city').val();
	$.ajax({
	       url: $crmServer+'/area/listChildArea.json',
	       type: "POST",
	       data:{'parenAreaId':province},
	       success: function(result) {
		       var parentId = $('#city');
				parentId.empty();    
		       	var dataList = new Array();  
		       	if(result.data!=null) {
		       		//北京和上海的单独处理
		       		if(province==1){
		       			city0 = 1;
		       			var option = $("<option>").text(pText).val(city0);
		       			$('#city').append(option);
		       		}else if(province==2){
		       			city0 = 2;
		       			var option = $("<option>").text(pText).val(city0);
		       			$('#city').append(option);
		       		}else{
		       			dataList = result.data;
		       			city0 = dataList[0].areaId;
		       		}
		       		$.ajax({
	       				url: $crmServer+'/area/listChildArea.json',
	      				 type: "POST",
	       				data:{'parenAreaId':city0},
	       				success: function(result) {
		       			
						$('#district').empty();    
		       			if(result.data!=null) {
		       				var dataList = result.data;
		       		
		       				for(var i=0; i<dataList.length; ++i) {
		       					var option = $("<option>").text(dataList[i].areaName).val(dataList[i].areaId);
		       					$('#district').append(option);
		       				}
		       			}
	       				}
	  				});
		       		for(var i=0; i<dataList.length; ++i) {
		       			var option = $("<option>").text(dataList[i].areaName).val(dataList[i].areaId);
		       			parentId.append(option);
		       		}
		       	}
	       }
	  });
	
}
</script>